<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="工厂:" prop="plantNo">
          <el-select v-model="formModel.plantNo" clearable filterable>
            <el-option
              v-for="item in plantOptions"
              :key="item.plantNo"
              :label="item.plantNo+'-'+item.plantNameC"
              :value="item.plantNo"
            />
          </el-select>
        </el-form-item>
        <el-form-item class="no-warn-item" label="装配单类型:" prop="modelFileNameKey">
          <hey-select v-model="formModel.modelFileNameKey" :in-clude-keys="['Car_BOM','Car_BOM_Model','Car_Door','Car_Meter','Car_Power','Car_Axle','Car_Subframe','Car_Frame','Car_Cow']" clcd="print_model_cd" />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button
              v-if="hasPermission('assembleForm_select')"
              type="primary"
              plain
              @click="queryList(false)"
            >查询
            </el-button>
            <el-button
              v-if="hasPermission('assembleForm_add')"
              type="primary"
              plain
              @click="handleAdd"
            >新增
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :table-data="tableData" :columns="columns">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="120"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span
              v-if="hasPermission('assembleForm_edit')"
              class="hey_tools_btn"
              @click="handleEdit(row)"
            >编辑</span>
            <span
              v-if="hasPermission('assembleForm_delete')"
              class="hey_tools_btn"
              @click="handleDelete(row)"
            >删除</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <el-dialog
      v-if="dialogVisible"
      v-dialogDrag
      :close-on-click-modal="false"
      title="装配单模板配置"
      :visible.sync="dialogVisible"
      width="60%"
    >
      <AssembleForm-mnt :page-type="operateType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>

  </div>
</template>

<script>

export default {
  name: 'AssembleFormList',
  components: {
    AssembleFormMnt: () => import('./assembleForm-mnt')
  },
  props: {},
  data() {
    return {
      plantOptions: [],
      dialogVisible: false,
      operateType: '',
      editData: {},
      tableData: [],
      formModel: {
        modelFileNameKey: '',
        plantNo: ''
      },
      columns: [
        { title: '工厂代码', key: 'plantNo' },
        { title: '工厂名称', key: 'plantNameC' },
        { title: '打印模板代码', key: 'modelFileNameKey' },
        { title: '打印模板名称', key: 'modelFileNameKey', clcd: 'print_model_cd' },
        { title: '打印顺序', key: 'printOrder' },
        { title: '配置代码', key: 'configNo' },
        { title: '配置描述', key: 'configDesc' },
        { title: '创建时间', key: 'createTime' },
        { title: '创建人', key: 'createUsername' },
        { title: '最后修改时间', key: 'lastUpdateTime' },
        { title: '最后修改人', key: 'lastUpdateUsername' }
      ]
    }
  },
  computed: {},
  mounted() {
    const param = { status: '1' }
    this.getPlantOptions(param)
  },
  methods: {
    // 获取工厂列表
    getPlantOptions(param) {
      this.get('/tmBasPlant/queryTmBasPlantList', param).then(res => {
        this.plantOptions = res
      })
    },
    queryList() {
      this.$refs.table.query('/assembleForm/pageAssembleForm', this.formModel, '', false)
    },
    handleAdd() {
      this.operateType = 'add'
      this.dialogVisible = true
    },
    handleEdit(row) {
      this.dialogVisible = true
      this.operateType = 'edit'
      this.editData = row || {}
    },
    handleDelete(row) {
      this.$sure('确认删除？', _ => {
        this.post('/assembleForm/deleteAssembleForm', {
          assembleFormId: row.assembleFormId,
          operateType: '03'
        }).then(_ => {
          this.$info('删除成功', this.queryList)
        })
      })
    }
  }
}
</script>
